package com.ztom.daily.n2022.m3;

/**
 * 各位相加
 * <p>
 * https://leetcode-cn.com/problems/add-digits/
 *
 * @author ZhangTao
 */
public class Day03AddDigits {

    public int addDigits1(int num) {
        if (num < 0) {
            return -1;
        }
        while (num >= 10) {
            int sum = 0;
            while (num > 0) {
                sum += num % 10;
                num /= 10;
            }
            num = sum;
        }

        return num;
    }

    public int addDigits(int num) {
        return (num - 1) % 9 + 1;
    }
}
